/*
 * PanelTowerSettingsDouble.java
 *
 * Created on January 15, 2008, 1:21 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package hextd.tower;

import hextd.util.Context;

/**
 *
 * @author  hylke
 */
public class PanelTowerSettingsDouble extends PanelTowerSettings {
    
    private String[] modes1;
    private String[] modes2;
    private int mode1 = 0;
    private int mode2 = 0;
    private Tower t;
    private Context c;
    private boolean loading = false;
    
    /** Creates new form PanelTowerSettingsDouble */
    public PanelTowerSettingsDouble(Tower t, Context c) {
        super(c);
        this.c = c;
        initComponents();
        this.t = t;
    }
    public void setModes(String[] modes) {
        System.err.println("PanelTowerSettingsDouble:setModes: should not be called for this class.");
    }
    public void setModes1(String[] modes) {
        this.loading = true;
        this.modes1 = modes;
        this.jComboBox_mode1.removeAllItems();
        for (int i=0; i<this.modes1.length; i++) {
            this.jComboBox_mode1.addItem(this.modes1[i]);
        }
        this.jComboBox_mode1.setSelectedIndex(this.mode1);
        this.jLabel_mode1.setText(this.modes1[this.mode1]);
        this.loading = false;
    }
    public void setModes2(String[] modes) {
        this.loading = true;
        this.modes2 = modes;
        this.jComboBox_mode2.removeAllItems();
        for (int i=0; i<this.modes2.length; i++) {
            this.jComboBox_mode2.addItem(this.modes2[i]);
        }
        this.jComboBox_mode2.setSelectedIndex(this.mode2);
        this.jLabel_mode2.setText(this.modes2[this.mode2]);
        this.loading = false;
        
    }
    public int getMode(int m) {
        if (m==1) {
            return this.mode1;
        } else if (m==2) {
            return this.mode2;
        }
        return -1;
    }
    
    public void setMode(int m, int v) {
        if (m==1) {
            this.mode1 = v;
            this.loading = true;
            this.jComboBox_mode1.setSelectedIndex(this.mode1);
            this.jLabel_mode1.setText(this.modes1[this.mode1]);
            this.loading = false;
            if (t.getMode(1) != this.mode1) {
                t.setMode(1, this.mode1);
            }
        } else if (m==2) {
            this.mode2 = v;
            this.loading = true;
            this.jComboBox_mode2.setSelectedIndex(this.mode2);
            this.jLabel_mode2.setText(this.modes2[this.mode2]);
            this.loading = false;
            if (t.getMode(2) != this.mode2) {
                t.setMode(2, this.mode2);
            }
        }
    }
    
    public int nextMode(int m) {
        if (m==1) {
            return this.nextMode1();
        } else if (m==2) {
            return this.nextMode2();
        } else {
            return -1;
        }
    }
    public int nextMode1() {
        this.mode1++;
        if (this.mode1 >= this.modes1.length) {
            this.mode1 = 0;
        }
        this.loading = true;
        this.jComboBox_mode1.setSelectedIndex(this.mode1);
        this.jLabel_mode1.setText(this.modes1[this.mode1]);
        this.loading = false;
        t.setMode(1, this.mode1);
        return this.mode1;
    }
    public int nextMode2() {
        this.mode2++;
        if (this.mode2 >= this.modes2.length) {
            this.mode2 = 0;
        }
        this.loading = true;
        this.jComboBox_mode2.setSelectedIndex(this.mode2);
        this.jLabel_mode2.setText(this.modes2[this.mode2]);
        this.loading = false;
        t.setMode(2, this.mode2);
        return this.mode2;
    }
    
    public void setEnabled(boolean enable) {
        this.jComboBox_mode1.setVisible(enable);
        this.jComboBox_mode2.setVisible(enable);
        this.jLabel_mode1.setVisible(!enable);
        this.jLabel_mode2.setVisible(!enable);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jComboBox_mode1 = new javax.swing.JComboBox();
        jComboBox_mode2 = new javax.swing.JComboBox();
        jLabel_mode1 = new javax.swing.JLabel();
        jLabel_mode2 = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        setBackground(this.c.colors.getColorBackGround());
        setForeground(this.c.colors.getColorForeGround());
        jLabel1.setBackground(this.c.colors.getColorBackGround());
        jLabel1.setForeground(this.c.colors.getColorForeGround());
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Target Modes");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel1, gridBagConstraints);

        jComboBox_mode1.setBackground(this.c.colors.getColorBackGround());
        jComboBox_mode1.setForeground(this.c.colors.getColorForeGround());
        jComboBox_mode1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox_mode1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_mode1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.01;
        add(jComboBox_mode1, gridBagConstraints);

        jComboBox_mode2.setBackground(this.c.colors.getColorBackGround());
        jComboBox_mode2.setForeground(this.c.colors.getColorForeGround());
        jComboBox_mode2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox_mode2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_mode2ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jComboBox_mode2, gridBagConstraints);

        jLabel_mode1.setBackground(this.c.colors.getColorBackGround());
        jLabel_mode1.setForeground(this.c.colors.getColorForeGround());
        jLabel_mode1.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel_mode1, gridBagConstraints);

        jLabel_mode2.setBackground(this.c.colors.getColorBackGround());
        jLabel_mode2.setForeground(this.c.colors.getColorForeGround());
        jLabel_mode2.setText("jLabel3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel_mode2, gridBagConstraints);

    }// </editor-fold>//GEN-END:initComponents
    
    private void jComboBox_mode1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode1ActionPerformed
        if (!this.loading) {
            this.mode1 = this.jComboBox_mode1.getSelectedIndex();
            this.c.setMode(this.t, 1, this.mode1);
        }
    }//GEN-LAST:event_jComboBox_mode1ActionPerformed
    
    private void jComboBox_mode2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode2ActionPerformed
        if (!this.loading) {
            this.mode2 = this.jComboBox_mode2.getSelectedIndex();
            this.c.setMode(this.t, 2, this.mode2);
        }
    }//GEN-LAST:event_jComboBox_mode2ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox_mode1;
    private javax.swing.JComboBox jComboBox_mode2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_mode1;
    private javax.swing.JLabel jLabel_mode2;
    // End of variables declaration//GEN-END:variables
    
}
